package com.appyvet.rangebarsample;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import org.junit.Before;
import org.junit.Test;

import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.app.Context;
import ohos.agp.components.Attr;
import ohos.agp.components.AttrSet;

import java.util.ArrayList;
import java.util.Optional;

import com.appyvet.materialrangebar.RangeBar;

/**
 * This class represents test cases
 * of application
 */
public class ExampleOhosTest {
    private static final float DELTA = 0.1f;
    private Context mContext;
    private AttrSet attrSet;

    /**
     * setUp
     */
    @Before
    public void setUp() {
        mContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();

        attrSet = new AttrSet() {
            @Override
            public Optional<String> getStyle() {
                return Optional.empty();
            }

            @Override
            public int getLength() {
                return 0;
            }

            @Override
            public Optional<Attr> getAttr(int i) {
                return Optional.empty();
            }

            @Override
            public Optional<Attr> getAttr(String s) {
                return Optional.empty();
            }
        };
    }

    @Test
    public void testBundleName() {
        final String actualBundleName = AbilityDelegatorRegistry.getArguments().getTestBundleName();
        assertEquals("com.appyvet.rangebarsample", actualBundleName);
    }

    @Test
    public void testIsRangeBar() {
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setRangeBarEnabled(true);
        assertTrue(bar.isRangeBar());
    }

    @Test
    public void testIsSeekBar() {
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setRangeBarEnabled(false);
        assertFalse(bar.isRangeBar());
    }

    @Test
    public void testRangeBarEnabled() {
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setEnabled(true);
        assertTrue(bar.isEnabled());
    }

    @Test
    public void testTickStart() {
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setTickStart(2);
        assertEquals(2, bar.getTickStart(), DELTA);
    }

    @Test
    public void testTickEnd() {
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setTickEnd(10);
        assertEquals(10, bar.getTickEnd(), DELTA);
    }

    @Test
    public void testTickInterval() {
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setTickInterval(2);
        assertEquals(2, bar.getTickInterval(), DELTA);
    }

    @Test
    public void testBarRounded() {
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setBarRounded(true);
        assertTrue(bar.isBarRounded());
    }

    @Test
    public void testTickTopLabels() {
        RangeBar bar = new RangeBar(mContext, attrSet);
        CharSequence[] topLabels = new CharSequence[4];
        topLabels[0] = "label1";
        topLabels[1] = "label2";
        topLabels[2] = "label3";
        topLabels[3] = "label4";
        bar.setTickTopLabels(topLabels);
        assertNotNull(bar.getTickTopLabels());
    }

    @Test
    public void testTickColors(){
        RangeBar bar = new RangeBar(mContext, attrSet);
        ArrayList<Integer> tickColors = new ArrayList<>();
        tickColors.add(987354631);
        tickColors.add(987266590);
        tickColors.add(786354427);
        tickColors.add(876354373);
        bar.setTickColors(tickColors);
        assertNotNull(bar.getTickColors());
    }

    @Test
    public void testLeftThumbColor(){
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setLeftThumbColor(87354623);
        assertEquals(87354623, bar.getLeftThumbColor());
    }

    @Test
    public void testRightThumbColor(){
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setRightThumbColor(97653467);
        assertEquals(97653467, bar.getRightThumbColor());
    }

    @Test
    public void testLeftPinValue(){
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setRangePinsByValue(1, 3); ;
        assertEquals(1, Float.parseFloat(bar.getLeftPinValue()), DELTA) ;
    }

    @Test
    public void testRightPinValue(){
        RangeBar bar = new RangeBar(mContext, attrSet);
        bar.setRangePinsByValue(2, 4); ;
        assertEquals(4, Float.parseFloat(bar.getRightPinValue()), DELTA) ;
    }
}